package com.moinut.studentattendancemanager.model.dbc;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @author MOILING
 */
public class DatabaseConnection {
    private static final String DB_DRIVER = "com.mysql.jdbc.Driver";
    private static final String DB_URL = "jdbc:mysql://localhost:3306/student_attendance";
    private static final String DB_USER = "moi";
    private static final String DB_PASS = "moi";

    private Connection connection = null;

    public DatabaseConnection() throws Exception {
        try {
            Class.forName(DB_DRIVER);
            this.connection = DriverManager.getConnection(DB_URL, DB_USER, DB_PASS);
        } catch (Exception ignored) {

        }
    }

    public Connection getConnection() {
        return connection;
    }

    public void close() throws Exception {
        if (this.connection != null) {
            this.connection.close();
        }
    }
}
